import request from "../request";

// 管理员登录
interface LoginData {
  account: string;
  password: string;
}
export const login = (data: LoginData) => {
  return request("/back/login", data, "POST");
};

// 获取分类
export const getCategory = () => {
  return request("/back/categories", {}, "GET");
};
// 删除分类
export const deleteCategory = (categoriesId: number) => {
  console.log("传过来的id", categoriesId);
  const path = "/back/categories/api?categoriesId=" + categoriesId;
  return request(path, {}, "DELETE");
};
// 添加分类
interface AddCategoryData {
  name: string;
}

export const addCategory = (data: AddCategoryData) => {
  return request("/back/categories/api", data, "POST");
};

// 获取所有文章
interface ArticleData {
  page: string;
  pageSize: string;
}

export const getAllArticle = (data: ArticleData) => {
  const url =
    "/back/article/all?page=" + data.page + "&pageSize=" + data.pageSize;
  return request(url, "GET");
};

// 删除文章
export const deleteArticle = (articleId: number) => {
  const path = "/back/article/api?articleId=" + articleId;
  return request(path, {}, "DELETE");
};

// 发布文章
interface PublishArticleData {
  content: string;
  title: string;
  categoriesId: number;
  tagsId: string;
  time: string;
}
export const publishArticle = (data: PublishArticleData) => {
  return request("/back/article/api", data, "POST");
};

// 获取标签
export const getLabel = () => {
  return request("/back/tags", {}, "GET");
};
// 新增标签
export const addLabel = (data: any) => {
  return request("/back/tags/api", data, "POST");
};
// 删除标签
export const deleteLabel = (tagsId: number) => {
  const path = "/back/tags/api?tagId=" + tagsId;
  return request(path, {}, "DELETE");
};
